package Cards;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-07-23
 * Time: 9:05
 */
//牌对象
class Card{
    public int rank;//数字
    public String suit;//花色

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public String toString() {
        return  rank + " " + suit ;
    }
}
public class CardDemo {
    public String[] suits = {"♥","♠","♣","♦"};
    //买一副扑克牌
    public List<Card> buyDeskCard(){
        List<Card> cards = new ArrayList<>();
        for (int i = 1; i <= 13 ; i++) {
            for (int j = 0; j < 4; j++) {
                Card card = new Card(i,suits[j]);
                cards.add(card);
            }
        }
        return cards;
    }
    //洗牌
    public void shellu(List<Card> cards){
        for (int i = cards.size()-1; i >1 ; i--) {
            Random random = new Random();
            int index = random.nextInt(i);
            swap(cards,i,index);
        }

    }
    public void swap(List<Card> cards, int i , int index){
        Card tmp = cards.get(i);
        cards.set(i,cards.get(index));
        cards.set(index,tmp);
    }
    //发牌 三个人轮流爪5张牌
    public List<List<Card>> idea(List<Card> cards){
        //三个人
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        //利用二维数组思想来轮流抓牌
        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);
        //5轮 每轮抓三张
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                //每删除一张牌，0下标对应的元素都会改变
                Card card = cards.remove(0);
                //hand1 hand2 hand3 分别抓牌
                hands.get(j).add(card);
            }
        }
        return hands;





    }

}
